package com.zzty.zzlp.dao;

import com.zzty.zzlp.entity.Chat;
import com.zzty.zzlp.entity.Group;
import com.zzty.zzlp.entity.GroupInfo;
import com.zzty.zzlp.entity.User_info;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface GroupMapper {


    @Insert("insert into chatGroup (groupId,userId) values (#{groupId},#{userId})")
    public void createGroup(Group group);

    @Select("select * from chatGroup where userId=#{userId}")
    public List<Group> searchGroup(Integer userId);

    @Select("select MAX(groupId) from chatGroup")
    public Integer searchMaxGroupId();

    @Insert("insert into groupInfo values (#{id},#{name})")
    public void setGroupInfo(@Param("id") Integer id,@Param("name") String name);

    @Select("select * from groupInfo where id = #{id}")
    public GroupInfo searchGroupName(@Param("id") Integer id);

    @Select("select * from chatGroup where userId = #{userId}")
    public List<Group> searchAllGroup(@Param("userId") Integer userId);

    @Select("select userId from chatGroup where groupId = #{groupId}")
    public List<Integer> searchUsersInGroup(@Param("groupId") Integer groupId);

    @Select("select user_id,photo from user_info")
    public List<User_info> searchUserInfos();

    @Select("select * from chat where (groupId = #{groupId} and toId = #{toId}) or (groupId = #{groupId} and fromId = #{toId}) GROUP BY time")
    public List<Chat> searchAllGroupMsg(@Param("groupId") Integer groupId,@Param("toId") Integer toId);
}
